﻿/**********************************************************************
/// <summary>
// Name of File     :   PageMessage.cs
// Author           :   Dupinder Singh
// Create date      :   28th Sep 2011
/// </summary>
************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Reflection;

namespace Crystal.CLL
{
    public static class ToolTipManager
    {
         #region Member Variable
        private static Dictionary<string, string> _currentToolTip = null;
        #endregion
        
        #region Constructors
        static ToolTipManager()
        {
            LoadToolTipFromXml();
        }

        #endregion
        
        #region Methods
        /// <summary>
        /// This Function is used to Reload Message From XML File it Check that Hashtable object Current is null
        /// then it Reload message from Xml Files
        /// </summary>
        public static void ReLoadMessagesFromXml()
        {
            _currentToolTip = null;
            LoadToolTipFromXml();
        }

        /// <summary>
        /// This Function is used to load Message From XML File it Check that Hashtable object Current is null
        /// then it Load message from Xml Files Otherwise it it doesnot Load message
        /// </summary>
        private static void LoadToolTipFromXml()
        {
            if (_currentToolTip == null)
            {
                DataSet dsToolTip = new DataSet();
                Assembly _assembly;
                _assembly = Assembly.GetExecutingAssembly();
                dsToolTip.ReadXml(_assembly.GetManifestResourceStream("Crystal.CLL.Components.EntityFiles.ToolTip.xml"));
                _currentToolTip = new Dictionary<string, string>();

                if (dsToolTip.Tables.Count != 0)
                {
                    DataTable dtToolTip = dsToolTip.Tables[0];
                    if (dtToolTip.Rows.Count != 0)
                    {
                        foreach (DataRow drToolTip in dtToolTip.Rows)
                            _currentToolTip.Add(Convert.ToString(drToolTip[0]), Convert.ToString(drToolTip[1]));
                    }
                    dtToolTip = null;
                }
                dsToolTip = null;
            }
        }
        
        /// <summary>
        /// Get The Message from Message Hashtable and format it with the argumaents passed.
        /// </summary>
        /// <param name="strMessageName">string</param>
        /// <param name="args">param object[]</param>       
        /// <returns>string</returns>
        /// 

        public static string GetToolTip(string tooltipText)
        {
            return (_currentToolTip.ContainsKey(tooltipText) == true ? _currentToolTip[tooltipText].ToString() : "");
        }

        ///// <summary>
        ///// Get The Message from Message Hashtable and format it with the argumaents passed.
        ///// </summary>
       
       
        #endregion
    }
}
